package dataMining.FP_Growth;


/**
 * ��ջ
 * @author qjt
 * ����ĳ������ݷ����ջ��
 * ȡ����Ӧ�ý�ȡ����Object����Downcast��ԭ������ 
 *
 */
class Stack{
	Elem top;
    Stack(){
        top=null;
    }
    class Elem{
        Object obj;
        Elem next;
        Elem(){
            obj=null;
            next=null;
        }
    }

	void push(Object obj){
		Elem temp;
		temp=top;
		top=new Elem();
		top.obj=obj;
		top.next=temp;
	}
	Object pop(){
		Elem temp;
		if (top!=null){
			temp=top;
			top=top.next;
			return temp.obj;
		}
		else return null;
	}
	/**
	 * ���һ��ת�õ���ջ
	 * */
	Stack Invert(){
		Stack s=new Stack();
		Elem e;
		e=top;
		while(e!=null){
		    s.push(e.obj);
		    e=e.next;
		}
		return s;
	}
	/**����һ����¡�Ķ�ջ*/
	public Stack clone(){
		Stack s=new Stack();
		Elem e,ee;
		e=top;
		ee=new Stack.Elem();
		s.top=ee;
		while(e!=null){
		    ee.obj=e.obj;
		    if (e.next!=null){
		        ee.next=new Stack.Elem();
		        ee=ee.next;
		    }    
		    e=e.next;
		}
		return s;
	}
	/**
	 * ��ն�ջ
	 * */
	void Empty(){
		top=null;
	}
	boolean IsEmpty(){
		if (top==null){
			return true;
		}
		else return false;
	}
	int Len(){
		int i;
		Elem t;
		for(i=0,t=top;t!=null;i++,t=t.next);
		return i;	
		
	}
	

}
